package com.fr.chart.axis;

import com.fr.base.Inter;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.base.equals.Equals;
import com.fr.report.cellElement.Formula;
import com.fr.util.Utils;
import java.awt.Color;
import java.util.HashMap;
import java.util.Map;

public class ValueAxis extends Axis
{
  private static final long serialVersionUID = 6083137730386866219L;
  public static final String XML_TAG = "ValueAxis";
  public static final String[] UNIT_STRING = { Inter.getLocText("DataFunction-None"), Inter.getLocText("Unit_Hundred"), Inter.getLocText("Unit_Thousand"), Inter.getLocText("Unit_Ten_Thousand"), Inter.getLocText("Unit_Ten") + Inter.getLocText("Unit_Ten_Thousand"), Inter.getLocText("Unit_Million"), Inter.getLocText("Unit_Thousand") + Inter.getLocText("Unit_Ten_Thousand"), Inter.getLocText("Unit_Hundred_Million"), Inter.getLocText("Unit_Billion") };
  private static Map unit = null;
  private boolean customIncrement;
  private double increment;
  private boolean customCrossValue;
  private double crossValue;
  private String showUnit;
  private boolean isLog;
  private boolean isPercentage;
  private boolean hasAlertValue;
  private Object alertValue;

  public static double getDivideUnit(String paramString)
  {
    if (unit == null)
    {
      unit = new HashMap();
      unit.put(UNIT_STRING[0], new Double(1.0D));
      double d = 100.0D;
      for (int i = 1; i < UNIT_STRING.length; ++i)
      {
        unit.put(UNIT_STRING[i], new Double(d));
        d *= 10.0D;
      }
      unit.put("10000", new Double(10000.0D));
      unit.put("100000", new Double(100000.0D));
      unit.put("10000000", new Double(10000000.0D));
      unit.put("100000000", new Double(100000000.0D));
    }
    return ((Double)unit.get(paramString)).doubleValue();
  }

  public ValueAxis()
  {
    this(2);
  }

  public ValueAxis(int paramInt)
  {
    this.customIncrement = false;
    this.increment = 0.0D;
    this.customCrossValue = false;
    this.crossValue = 0.0D;
    this.showUnit = null;
    this.isLog = false;
    this.isPercentage = false;
    this.hasAlertValue = false;
    this.position = paramInt;
    setMainGridStyle(1);
    setMainGridColor(new Color(237, 237, 237));
  }

  public void setCustomIncrement(boolean paramBoolean)
  {
    this.customIncrement = paramBoolean;
  }

  public boolean isCustomIncrement()
  {
    return this.customIncrement;
  }

  public void setIncrement(double paramDouble)
  {
    this.increment = paramDouble;
  }

  public double getIncrement()
  {
    return this.increment;
  }

  public void setCustomCrossValue(boolean paramBoolean)
  {
    this.customCrossValue = paramBoolean;
  }

  public boolean isCustomCrossValue()
  {
    return this.customCrossValue;
  }

  public void setCrossValue(double paramDouble)
  {
    this.crossValue = paramDouble;
  }

  public double getCrossValue()
  {
    return this.crossValue;
  }

  public void setHasAlertValue(boolean paramBoolean)
  {
    this.hasAlertValue = paramBoolean;
  }

  public boolean hasAlertValue()
  {
    return this.hasAlertValue;
  }

  public void setAlertValue(Object paramObject)
  {
    this.alertValue = paramObject;
  }

  public Object getAlertValue()
  {
    return this.alertValue;
  }

  public void setShowUnit(String paramString)
  {
    this.showUnit = paramString;
  }

  public String getShowUnit()
  {
    return this.showUnit;
  }

  public void setIsLog(boolean paramBoolean)
  {
    this.isLog = paramBoolean;
  }

  public boolean isLog()
  {
    return this.isLog;
  }

  public void setPercentage(boolean paramBoolean)
  {
    this.isPercentage = paramBoolean;
  }

  public boolean isPercentage()
  {
    return this.isPercentage;
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof ValueAxis))
      return false;
    ValueAxis localValueAxis = (ValueAxis)paramObject;
    if (!(super.equals(localValueAxis)))
      return false;
    if (localValueAxis.isCustomIncrement() != isCustomIncrement())
      return false;
    if (localValueAxis.getIncrement() != getIncrement())
      return false;
    if (localValueAxis.isCustomCrossValue() != isCustomCrossValue())
      return false;
    if (localValueAxis.getCrossValue() != getCrossValue())
      return false;
    if (!(Equals.equals(localValueAxis.getShowUnit(), getShowUnit())))
      return false;
    if (localValueAxis.isLog() != isLog())
      return false;
    if (localValueAxis.hasAlertValue() != hasAlertValue())
      return false;
    return ((!(localValueAxis.hasAlertValue)) || (Equals.equals(localValueAxis.getAlertValue(), getAlertValue())));
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str1;
      String str2 = paramXMLableReader.getTagName();
      if (str2.equals("AxisRange"))
      {
        if ((str1 = paramXMLableReader.getAttr("minValue")) != null)
        {
          setCustomMinValue(true);
          setMinValue(Double.parseDouble(str1));
        }
        if ((str1 = paramXMLableReader.getAttr("maxValue")) != null)
        {
          setCustomMaxValue(true);
          setMaxValue(Double.parseDouble(str1));
        }
      }
      else if (str2.equals("AxisRangeIncr"))
      {
        if ((str1 = paramXMLableReader.getAttr("value")) != null)
          setIncrement(Double.parseDouble(str1));
        if (getIncrement() > 0.0D)
          setCustomIncrement(true);
      }
      else if ("Cross".equals(str2))
      {
        if ((str1 = paramXMLableReader.getAttr("value")) != null)
        {
          setCrossValue(Double.parseDouble(str1));
          setCustomCrossValue(true);
        }
      }
      else if ("Log".equals(str2))
      {
        if ((str1 = paramXMLableReader.getAttr("value")) != null)
          setIsLog(Boolean.valueOf(str1).booleanValue());
      }
      else
      {
        Object localObject;
        if (str2.equals("AxisAlert"))
        {
          if ((str1 = paramXMLableReader.getAttr("startValue")) != null)
          {
            if (str1.startsWith("="))
              str1 = str1.substring(1);
            if (this.alertValue == null)
            {
              this.alertValue = new Formula("=[" + str1 + "]");
            }
            else if (this.alertValue instanceof Formula)
            {
              localObject = this.alertValue.toString();
              ((Formula)this.alertValue).setContent("=[" + ((String)localObject).substring(2, ((String)localObject).length() - 1) + "," + str1 + "]");
            }
          }
          if ((str1 = paramXMLableReader.getAttr("endValue")) != null)
          {
            if (str1.startsWith("="))
              str1 = str1.substring(1);
            if (this.alertValue == null)
            {
              this.alertValue = new Formula("=[" + str1 + "]");
            }
            else if (this.alertValue instanceof Formula)
            {
              localObject = this.alertValue.toString();
              ((Formula)this.alertValue).setContent("=[" + ((String)localObject).substring(2, ((String)localObject).length() - 1) + "," + str1 + "]");
            }
          }
          if ((str1 = paramXMLableReader.getAttr("alertValue")) != null)
            this.alertValue = new Formula(str1);
          setHasAlertValue(true);
        }
        else if (str2.equals("ShowUnit"))
        {
          if ((str1 = paramXMLableReader.getAttr("value")) != null)
          {
            localObject = Utils.string2Number(str1);
            if (localObject != null)
            {
              HashMap localHashMap = new HashMap();
              localHashMap.put("10000", "万");
              localHashMap.put("100000", "十万");
              localHashMap.put("10000000", "千万");
              localHashMap.put("100000000", "亿");
              str1 = localHashMap.get(str1).toString();
            }
            setShowUnit(str1);
          }
        }
        else if (str2.equals("Percentage"))
        {
          if ((str1 = paramXMLableReader.getAttr("value")) != null)
            setPercentage(Boolean.valueOf(str1).booleanValue());
        }
      }
    }
    super.readXML(paramXMLableReader);
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    writeXML(paramXMLPrintWriter, "ValueAxis");
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter, String paramString)
  {
    paramXMLPrintWriter.startTAG(paramString).attr("class", getClass().getName());
    super.writeXML(paramXMLPrintWriter);
    if (this.isPercentage)
      paramXMLPrintWriter.startTAG("Percentage").attr("value", this.isPercentage).end();
    if ((isCustomIncrement()) && (getIncrement() > 0.0D))
      paramXMLPrintWriter.startTAG("AxisRangeIncr").attr("value", getIncrement()).end();
    if (isCustomCrossValue())
      paramXMLPrintWriter.startTAG("Cross").attr("value", getCrossValue()).end();
    if (getShowUnit() != null)
      paramXMLPrintWriter.startTAG("ShowUnit").attr("value", getShowUnit()).end();
    if (isLog())
      paramXMLPrintWriter.startTAG("Log").attr("value", this.isLog).end();
    if (hasAlertValue())
      paramXMLPrintWriter.startTAG("AxisAlert").attr("alertValue", getAlertValue().toString()).end();
    paramXMLPrintWriter.end();
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    localJSONObject.put("crossValue", this.crossValue);
    localJSONObject.put("customCrossValue", this.customCrossValue);
    localJSONObject.put("customIncrement", this.customIncrement);
    localJSONObject.put("alertValue", this.alertValue);
    localJSONObject.put("hasAlertValue", this.hasAlertValue);
    localJSONObject.put("increment", this.increment);
    localJSONObject.put("isLog", this.isLog);
    localJSONObject.put("isPercentage", this.isPercentage);
    localJSONObject.put("showUnit", this.showUnit);
    return localJSONObject;
  }
}